////////////////////////////////////////////////////////////
// Workfile : PersonReader.cpp
// Author : Andreas Lehner
// Date : 5.11.2012
// Description : read information of a person IMPLEMENTATION
// Remarks : 0
// Revision : 1
////////////////////////////////////////////////////////////
#include "PersonReader.h"
#include "Person.h"
#include <string>
#include <vector>

using namespace std;

//read a person
void PersonReader::DoRead(std::string const& line, IRead *read){
	//variables of a Person
	string firstname;
	string secondname;
	size_t index;
	//iterator on beginning of a string
	string::const_iterator start = line.begin();
	//read members of a Person
	if (start == line.end()){
		throw "PersonReader: first name expected...";
	}
	firstname = readWord(start, line.end());
	if (start == line.end()){
		throw "PersonReader: second name expected...";
	}
	secondname = readWord(start, line.end());
	if (start == line.end()){
		throw "PersonReader: index expected...";
	}
	index = readNumber(start, line.end());

	//save information in Person
	Person p(firstname, secondname, index);
	//add Person to mPersons of AddressManager
	read->addPerson(p);
}